草庐IT

Python mysql.connector 超时

全部标签

java - 使用带超时的 sping 的 restTemplate,如何检测超时?

我已经按如下方式初始化了我的restTemplate:HttpClienthttpClient=HttpClientBuilder.create().build();HttpComponentsClientHttpRequestFactoryrequestFactory=newHttpComponentsClientHttpRequestFactory(httpClient);requestFactory.setConnectTimeout(1000);requestFactory.setReadTimeout(1000);restTemplate=newRestTemplate(re

python - 如何从 Twisted 的 deferToThread API 向 Deferred 添加超时?

fromtwisted.internetimportreactorfromtwisted.internetimportthreadsfromtwisted.internetimportdeferimporttimedefworker(arg):print'Helloworld'time.sleep(10)return1defrun():print'Startingworkers'l=[]forxinrange(2):l.append(threads.deferToThread(worker,x))returndefer.DeferredList(l)defres(results):pr

python - 使多处理函数超时

我需要对使用一些多处理内容的python函数设置时间限制(我不知道这是否重要)。像这样:function(a_list):p1=Process(a_list[0:len(a_list/2)])p2=Process(a_list[len(a_list)/2:len(a_list)])//startandjoinp1,p2我环顾网络,发现了一个超时装饰器,但它看起来非常棘手和冗长(我是装饰器的新手)。我想要的是一件简单的事情。编辑:我想我把它想得太简单了。我的程序迭代上述函数并将结果存储在如下列表中:while(something):retval=function(some_list)#h

python - 使多处理函数的装饰器超时

这个装饰器是直接从我在网上找到的一个例子中拿来的:classTimedOutExc(Exception):passdeftimeout(timeout):defdecorate(f):defhandler(signum,frame):raiseTimedOutExc()defnew_f(*args,**kwargs):old=signal.signal(signal.SIGALRM,handler)signal.alarm(timeout)try:result=f(*args,**kwargs)exceptTimedOutExc:returnNonefinally:signal.sig

python - 属性错误 : module 'mysql' has no attribute 'connector'

我正在运行Ubuntu16.04,尝试在python中连接到mysql:importmysqlusername='root'cnx=mysql.connector.connect(user=username,database='db')cnx.close()但是我得到一个错误:File"pysql1.py",line4,incnx=mysql.connector.connect(user=username,database='db')AttributeError:module'mysql'hasnoattribute'connector'我通过下载包安装了mysqlpython模块he

Python-LDAP simple_bind_s 超时

有没有办法在python-LDAP中手动为“simple_bind_s”设置超时?我已经测试了ldapObject.timeout=10它对我不起作用。有什么想法吗?提前致谢.. 最佳答案 为ldap对象设置选项ldap.OPT_NETWORK_TIMEOUT。importldapl=ldap.initialize('ldap://servername:389')l.set_option(ldap.OPT_NETWORK_TIMEOUT,10.0)l.simple_bind_s('username','password')如果达到指

python - 未使用预期超时,仅使用默认值 30

我正在尝试执行一个冗长的操作,但带有超时参数的预期似乎并没有改变超时异常被触发之前的时间长度。这是我的代码:child=pexpect.spawn('scpfileuser@:/temp',timeout=300)whichMatched=child.expect(['(?i)Password','Areyousureyouwanttocontinueconnecting(yes/no)?'],timeout=300)异常显示超时=30,这是默认值。after:match:Nonematch_index:Noneexitstatus:Noneflag_eof:Falsepid:6222

python - 如何在 matplotlib 中为 pyplot.show() 设置超时?

我正在使用python的matplotlib来绘制图形。我想画一个带有超时的图形,比如3秒,然后窗口将关闭以在代码上移动。我知道pyplot.show()会创建一个无限超时的阻塞窗口;pyplot.show(block=False)或pyplot.draw()将使窗口非阻塞。但我想要的是让代码阻塞几秒钟。我想到了一个想法,我可能会使用事件处理程序或其他东西,但仍然不太清楚如何解决这个问题。有什么简单优雅的解决方案吗?假设我的代码如下:绘图.py:importmatplotlib.pyplotasplt#Drawsomethingplt.show()#Blockornot?

python - 告诉我为什么这不会以超时错误结束(selenium 2 webdriver)?

fromseleniumimportwebdriverfromselenium.webdriver.support.uiimportWebDriverWaitbrowser=webdriver.Firefox()browser.get("http://testsite.com")element=WebDriverWait(browser,10).until(lambdabrowser:browser.find_element_by_id("element"))element.click()#itactuallygoestopagehttp://testsite.com/test-pag

python - 如何测试 nginx 代理超时

目标:我想在非常简单的场景中测试所有Nginx代理超时参数。我的第一种方法是创建非常简单的HTTP服务器并设置一些超时:在监听和接受之间测试proxy_connect_timeout在接受和阅读之间测试proxy_send_timeout在读取和发送之间测试proxy_read_timeout测试:1)服务器代码(python):importsocketimportosimporttimeimportthreadingdefhttp_resp(conn):conn.send("HTTP/1.1200OK\r\n")conn.send("Content-Length:0\r\n")con